package com.jwsoft.manager.core.integration.dataStatistics.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.assistant.core.utils.SessionUtil;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.bifang.module.base.common.vo.dict.DictAreaVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.excel.ExcelModelVO;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.core.helper.DictHelper;
import com.bifang.module.base.core.helper.ExcelCommonHelper;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.system.core.integration.impl.ExcelIntegrationImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.enums.EduEnrollPreDictEnum;
import com.jwsoft.manager.common.enums.SchoolCategoryEnum;
import com.jwsoft.manager.common.enums.SchoolNatureEnum;
import com.jwsoft.manager.common.vo.dataStatistics.enroll.*;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.core.dao.mapper.EduAddressSchoolDifferentStreetMapper;
import com.jwsoft.manager.core.dao.model.EduAddressSchoolDifferentStreet;
import com.jwsoft.manager.core.dao.model.EduArea;
import com.jwsoft.manager.core.dao.model.EduSchoolConfig;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.dataStatistics.DyEnrollDataIntegration;
import com.jwsoft.manager.core.integration.dataStatistics.EnrollDataIntegration;
import com.jwsoft.manager.core.util.EduHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import static org.springframework.beans.BeanUtils.copyProperties;

@ApiService(funcCode = "DyEnrollData", title = "报名相关数据统计")
@Slf4j
public class DyEnrollDataIntegrationImpl implements DyEnrollDataIntegration {
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private EduAreaService eduAreaService;
    @Autowired
    private DictHelper dictHelper;
    @Autowired
    public ExcelIntegrationImpl excelIntegration;
    @Value("${spring.servlet.multipart.location}")
    private String tempPath;
    @Autowired
    ExcelCommonHelper excelCommonHelper;
    @Autowired
    DyEduStudentEnrollService eduStudentEnrollService;
    @Autowired
    EduSchoolConfigService eduSchoolConfigService;
    @Autowired
    DictIntegration dictIntegration;
    @Autowired
    EduAddressSchoolDifferentStreetService differentStreetService;
    @Autowired
    EduAddressSchoolDifferentStreetMapper differentStreetMapper;
    @Autowired
    EduSchoolService eduSchoolService;

    @Override
    @OpApi(funcCode = "DyEnrollData0001", title = "获取辖区内报名过但未被录取人员清单", funcType = FuncTypeEnum.query)
    public PageInfo<NoEnrollStudentVO> queryNoEnrollStudent(EnrollStudentQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<NoEnrollStudentVO> list = eduStudentEnrollService.queryNoEnrollStudent(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<NoEnrollStudentVO> pageInfo = new PageInfo<>(list);
        List<String> streetList = list.stream().map(NoEnrollStudentVO::getStreet).distinct().collect(Collectors.toList());
        QueryWrapper<EduArea> areaQueryWrapper = new QueryWrapper<>();
        areaQueryWrapper.lambda().in(EduArea::getLocalCode, streetList);
        List<EduArea> areaList =
                eduAreaService.list(areaQueryWrapper);

        Map<String, String> streetMap = areaList.stream().collect(Collectors.toMap(EduArea::getLocalCode, EduArea::getAreaName));
        for (NoEnrollStudentVO studentVO : pageInfo.getList()) {
            if (!ObjectUtils.isEmpty(studentVO.getStreet())) {
                studentVO.setStreetName(streetMap.get(studentVO.getStreet()));
            }
            if (!ObjectUtils.isEmpty(studentVO.getAreaCode())) {
                studentVO.setAreaName(dictHelper.getAreaNameByCode(studentVO.getAreaCode()));
            }

            if (!ObjectUtils.isEmpty(studentVO.getSchoolCategory())) {
                SchoolCategoryEnum schoolCategoryEnum = SchoolCategoryEnum.getByType(studentVO.getSchoolCategory());
                if (schoolCategoryEnum != null) {
                    studentVO.setSchoolCategoryName(schoolCategoryEnum.getName());
                }
            }
            if (!ObjectUtils.isEmpty(studentVO.getSchoolNature())) {
                SchoolNatureEnum schoolNatureEnum = SchoolNatureEnum.getByType(studentVO.getSchoolNature());
                if (schoolNatureEnum != null) {
                    studentVO.setSchoolNatureName(schoolNatureEnum.getName());
                }
            }
        }
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0002", title = "报名相关数据统计导出", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downloadData(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0003", title = "学校招生情况统计", funcType = FuncTypeEnum.query)
    public PageInfo<EnrollStatisticsVO> enrollStatistics(EnrollStudentQueryVO vo) {
        if (ObjectUtils.isEmpty(vo.getYear())) {
            throw new AppException("招生年度不能为空");
        }

        //查出账号配置的行政区划及子级行政区划
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(new DictAreaVO());
        List<String> areaList = districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        vo.setAreaList(areaList);
        List<EnrollStatisticsVO> list = eduStudentEnrollService.enrollStatistics(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }

        PageInfo<EnrollStatisticsVO> pageInfo = new PageInfo<>(list);


//        QueryWrapper<EduSchoolConfig> schoolConfigQueryWrapper = new QueryWrapper<>();
//        schoolConfigQueryWrapper.lambda().eq(!ObjectUtils.isEmpty(vo.getAreaCode()), EduSchoolConfig::getAreaCode, vo.getAreaCode())
//                .eq(!ObjectUtils.isEmpty(vo.getSchoolId()), EduSchoolConfig::getSchoolId, vo.getSchoolId())
//                .eq(!ObjectUtils.isEmpty(vo.getYear()), EduSchoolConfig::getYear, vo.getYear())
//                .in(EduSchoolConfig::getAreaCode, areaList);
//        List<EduSchoolConfig> schoolConfigList = eduSchoolConfigService.list(schoolConfigQueryWrapper);
//        Map<String, Integer> schoolConfigMap = new HashMap<>();
//
//        if (!CollectionUtils.isEmpty(schoolConfigList)) {
//            schoolConfigMap = schoolConfigList.stream().collect(Collectors.groupingBy(EduSchoolConfig::getSchoolId, Collectors.summingInt(EduSchoolConfig::getEnrolment)));
//        }


        //审核不通过数据
        List<EnrollStatisticsVO> authNoList = eduStudentEnrollService.getauthNoList(vo);
        Map<String, Integer> authNoMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(authNoList)) {
            authNoMap = authNoList.stream().collect(Collectors.groupingBy(EnrollStatisticsVO::getSchoolId, Collectors.summingInt(EnrollStatisticsVO::getSchoolBtgNum)));
        }


        for (EnrollStatisticsVO statisticsVO : pageInfo.getList()) {
            //  statisticsVO.setPlanStudentNum(schoolConfigMap.get(statisticsVO.getSchoolId()));
            if (statisticsVO.getEnrollNum() != null) {
                statisticsVO.setAdmitBxNum(statisticsVO.getAdmitNum() - statisticsVO.getAdmitDiversionNum());
                statisticsVO.setPlanStudentRemainNum(statisticsVO.getPlanStudentNum() - statisticsVO.getAdmitNum());

                statisticsVO.setSchoolBtgNum(authNoMap.get(statisticsVO.getSchoolId()) == null ? 0 : authNoMap.get(statisticsVO.getSchoolId()));
                statisticsVO.setEduBtgNum(statisticsVO.getBtgNum() - statisticsVO.getSchoolBtgNum());

                statisticsVO.setSchoolAuditNum(statisticsVO.getSchoolDshNum() + statisticsVO.getSchoolTgNum() + statisticsVO.getSchoolBtgNum());
                statisticsVO.setEduAuditNum(statisticsVO.getEduDshNum() + statisticsVO.getEduTgNum() + statisticsVO.getEduBtgNum());
            }


        }
        dictHelper.valueToName(pageInfo.getList(), Arrays.asList(EduEnrollPreDictEnum.values()));
        return pageInfo;
    }


    @Override
    @OpApi(funcCode = "DyEnrollData0004", title = "模拟学校招生情况统计", funcType = FuncTypeEnum.query)
    public PageInfo<EnrollStatisticsVO> enrollStatisticsImitate(EnrollStudentQueryVO vo) {
        if (ObjectUtils.isEmpty(vo.getYear())) {
            throw new AppException("招生年度不能为空");
        }
        //查出账号配置的行政区划及子级行政区划
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(new DictAreaVO());
        List<String> areaList = districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        vo.setAreaList(areaList);
        List<EnrollStatisticsVO> list = eduStudentEnrollService.enrollStatisticsImitate(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }

        PageInfo<EnrollStatisticsVO> pageInfo = new PageInfo<>(list);


        QueryWrapper<EduSchoolConfig> schoolConfigQueryWrapper = new QueryWrapper<>();
        schoolConfigQueryWrapper.lambda().eq(!ObjectUtils.isEmpty(vo.getAreaCode()), EduSchoolConfig::getAreaCode, vo.getAreaCode())
                .eq(!ObjectUtils.isEmpty(vo.getSchoolId()), EduSchoolConfig::getSchoolId, vo.getSchoolId())
                .eq(!ObjectUtils.isEmpty(vo.getYear()), EduSchoolConfig::getYear, vo.getYear())
                .in(EduSchoolConfig::getAreaCode, areaList);
        List<EduSchoolConfig> schoolConfigList = eduSchoolConfigService.list(schoolConfigQueryWrapper);
        Map<String, Integer> schoolConfigMap = new HashMap<>();

        if (!CollectionUtils.isEmpty(schoolConfigList)) {
            schoolConfigMap = schoolConfigList.stream().collect(Collectors.groupingBy(EduSchoolConfig::getSchoolId, Collectors.summingInt(EduSchoolConfig::getEnrolment)));
        }


        //审核不通过数据
        List<EnrollStatisticsVO> authNoList = eduStudentEnrollService.getauthNoListImitate(vo);
        Map<String, Integer> authNoMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(authNoList)) {
            authNoMap = authNoList.stream().collect(Collectors.groupingBy(EnrollStatisticsVO::getSchoolId, Collectors.summingInt(EnrollStatisticsVO::getSchoolBtgNum)));
        }


        for (EnrollStatisticsVO statisticsVO : pageInfo.getList()) {
            if (statisticsVO.getEnrollNum() != null) {
                statisticsVO.setPlanStudentNum(schoolConfigMap.get(statisticsVO.getSchoolId()));
                statisticsVO.setSchoolBtgNum(authNoMap.get(statisticsVO.getSchoolId()) == null ? 0 : authNoMap.get(statisticsVO.getSchoolId()));
                statisticsVO.setEduBtgNum(statisticsVO.getBtgNum() - statisticsVO.getSchoolBtgNum());
                statisticsVO.setSchoolAuditNum(statisticsVO.getSchoolDshNum() + statisticsVO.getSchoolTgNum() + statisticsVO.getSchoolBtgNum());
                statisticsVO.setEduAuditNum(statisticsVO.getEduDshNum() + statisticsVO.getEduTgNum() + statisticsVO.getEduBtgNum());
            }

        }
        dictHelper.valueToName(pageInfo.getList(), Arrays.asList(EduEnrollPreDictEnum.values()));
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0005", title = "学校招生情况统计导出", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downloadEnrollData(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setEnrollData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0006", title = "模拟学校招生情况统计", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downloadEnrollDataImitate(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setEnrollDataImitate(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    private void setData(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EnrollStudentQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            String total = "0";
            boolean hasNextPage = false;
            List<Map<String, Object>> list = new ArrayList<>();
            if (vo.getModelCode().equals("queryNoEnrollStudent")) {
                PageInfo<NoEnrollStudentVO> pageInfo = queryNoEnrollStudent(vo);
                total = String.valueOf(pageInfo.getTotal());
                if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                    for (NoEnrollStudentVO studentVO : pageInfo.getList()) {
                        list.add(BeanUtil.beanToMap(studentVO, false, true));
                    }
                }
                hasNextPage = pageInfo.isHasNextPage();
            } else {
                throw new AppException("导出类型未开发相应功能");
            }

            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeMap(excelWriter, list);
            } else {
                excelCommonHelper.writeMap(excelWriter, list);
            }
            if (hasNextPage) {
                pageNum = pageNum + 1;
                setData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    private void setEnrollData(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EnrollStudentQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            String total = "0";
            boolean hasNextPage = false;
            List<Map<String, Object>> list = new ArrayList<>();
            if (StringUtils.isNotBlank(vo.getModelCode())) {
                PageInfo<EnrollStatisticsVO> pageInfo = enrollStatistics(vo);
                total = String.valueOf(pageInfo.getTotal());
                if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                    for (EnrollStatisticsVO studentVO : pageInfo.getList()) {
                        list.add(BeanUtil.beanToMap(studentVO, false, true));
                    }
                }
                hasNextPage = pageInfo.isHasNextPage();
            } else {
                throw new AppException("导出类型未开发相应功能");
            }

            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeMap(excelWriter, list);
            } else {
                excelCommonHelper.writeMap(excelWriter, list);
            }
            if (hasNextPage) {
                pageNum = pageNum + 1;
                setData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }

    private void setEnrollDataImitate(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EnrollStudentQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            String total = "0";
            boolean hasNextPage = false;
            List<Map<String, Object>> list = new ArrayList<>();
            if (StringUtils.isNotBlank(vo.getModelCode())) {
                PageInfo<EnrollStatisticsVO> pageInfo = enrollStatisticsImitate(vo);
                total = String.valueOf(pageInfo.getTotal());
                if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                    for (EnrollStatisticsVO studentVO : pageInfo.getList()) {
                        list.add(BeanUtil.beanToMap(studentVO, false, true));
                    }
                }
                hasNextPage = pageInfo.isHasNextPage();
            } else {
                throw new AppException("导出类型未开发相应功能");
            }

            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeMap(excelWriter, list);
            } else {
                excelCommonHelper.writeMap(excelWriter, list);
            }
            if (hasNextPage) {
                pageNum = pageNum + 1;
                setData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }


    @Override
    @OpApi(funcCode = "DyEnrollData0031", title = "未被任何一所学校关联(排除服务区)", funcType = FuncTypeEnum.query)
    public PageInfo<NoAssociatedAddressVO> noAssociatedAddress(EnrollStudentQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<NoAssociatedAddressVO> list = eduStudentEnrollService.noAssociatedAddress(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<NoAssociatedAddressVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0032", title = "未被任何一所学校关联(排除服务区)导出", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downNoAssociatedAddress(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setJhData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0033", title = "同学段学校关联相同地址", funcType = FuncTypeEnum.query)
    public PageInfo<SameAddressSchoolVO> sameAddressSchool(EnrollStudentQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<SameAddressSchoolVO> list = eduStudentEnrollService.sameAddressSchool(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<SameAddressSchoolVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0034", title = "同学段学校关联相同地址导出", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downsameAddressSchool(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setJhData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0035", title = "同学段学校关联相同地址详情", funcType = FuncTypeEnum.query)
    public PageInfo<SameAddressSchoolDetailVO> sameAddressSchoolDetail(EnrollStudentQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<SameAddressSchoolDetailVO> list = eduStudentEnrollService.sameAddressSchoolDetail(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<SameAddressSchoolDetailVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0045", title = "学校查询同学段学校关联相同地址详情", funcType = FuncTypeEnum.query,checkPrivilege = BoolEnum.FALSE)
    public PageInfo<SameAddressSchoolDetailVO> sameAddressSchoolDetailSchool(EnrollStudentQueryVO vo) {
        String schoolId = SessionUtil.getOrgId();
        if (StringUtils.isBlank(schoolId)) {
            throw new AppException("当前账号未绑定学校");
        }
        EduSchoolVO school = eduSchoolService.getDetail(schoolId);
        if (ObjectUtils.isEmpty(school)){
            throw new AppException("该学校不存在，数据异常！");
        }
        vo.setSchoolId(school.getOrgId());
        vo.setSchoolCategory(school.getSchoolCategory());
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<SameAddressSchoolDetailVO> list = eduStudentEnrollService.sameAddressSchoolDetailSchool(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<SameAddressSchoolDetailVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0036", title = "同学段学校关联相同地址详情导出", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downsameAddressSchoolDetail(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setJhData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0037", title = "同学段服务区关联正学区未关联地址", funcType = FuncTypeEnum.query)
    public PageInfo<ServerRelationNoSchoolRelataionVO> serverRelationButNoAssociatedAddress(EnrollStudentQueryVO vo) {
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<ServerRelationNoSchoolRelataionVO> list = eduStudentEnrollService.serverRelationButNoAssociatedAddress(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<ServerRelationNoSchoolRelataionVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void downserverRelationButNoAssociatedAddress(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);
        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setJhData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0007", title = "学校各类情况统计", funcType = FuncTypeEnum.query)
    public PageInfo<EnrollStatisticsVO> allKindStatistic(EnrollStudentQueryVO vo) {
        if (ObjectUtils.isEmpty(vo.getYear())) {
            throw new AppException("招生年度不能为空");
        }

        //查出账号配置的行政区划及子级行政区划
        List<SelectVO> districtByOrg = dictIntegration.getDistrictByOrg(new DictAreaVO());
        List<String> areaList = districtByOrg.stream().map(SelectVO::getDictKey).collect(Collectors.toList());
        vo.setAreaList(areaList);
        List<EnrollStatisticsVO> list = eduStudentEnrollService.allKindStatistic(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }

        PageInfo<EnrollStatisticsVO> pageInfo = new PageInfo<>(list);




        //审核不通过数据
        List<AuthNoAllKindVO> authNoList = eduStudentEnrollService.getauthNoAllKindList(vo);
        Map<String, AuthNoAllKindVO> authNoMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(authNoList)) {
            authNoMap = authNoList.stream().collect(Collectors.toMap(AuthNoAllKindVO::getSchoolId, a->a, (k1, k2) -> k1));
        }


        for (EnrollStatisticsVO statisticsVO : pageInfo.getList()) {
            //  statisticsVO.setPlanStudentNum(schoolConfigMap.get(statisticsVO.getSchoolId()));
            if (statisticsVO.getEnrollNum() != null) {
                statisticsVO.setPlanStudentRemainNum(statisticsVO.getPlanStudentNum() - statisticsVO.getAdmitNum());

                AuthNoAllKindVO authNoAllKindVO = authNoMap.get(statisticsVO.getSchoolId());
                if(authNoAllKindVO!=null){
                    statisticsVO.setSchoolBtgNum(authNoAllKindVO.getSchoolBtgNum());
                    statisticsVO.setSchoolBtgNumFhyz(authNoAllKindVO.getSchoolBtgNumFhyz());
                    statisticsVO.setSchoolBtgNumFhyzFwq(authNoAllKindVO.getSchoolBtgNumFhyzFwq());
                    statisticsVO.setSchoolBtgNumYfwh(authNoAllKindVO.getSchoolBtgNumYfwh());
                    statisticsVO.setSchoolBtgNumYhwf(authNoAllKindVO.getSchoolBtgNumYhwf());
                    statisticsVO.setSchoolBtgNumHj(authNoAllKindVO.getSchoolBtgNumHj());
                    statisticsVO.setSchoolBtgNumFc(authNoAllKindVO.getSchoolBtgNumFc());
                    statisticsVO.setSchoolBtgNumSb(authNoAllKindVO.getSchoolBtgNumSb());
                    statisticsVO.setSchoolBtgNumJzz(authNoAllKindVO.getSchoolBtgNumJzz());
                    statisticsVO.setSchoolBtgNumZcap(authNoAllKindVO.getSchoolBtgNumZcap());


                    statisticsVO.setEduBtgNum(authNoAllKindVO.getEduBtgNum());
                    statisticsVO.setEduBtgNumFhyz(authNoAllKindVO.getEduBtgNumFhyz());
                    statisticsVO.setEduBtgNumFhyzFwq(authNoAllKindVO.getEduBtgNumFhyzFwq());
                    statisticsVO.setEduBtgNumYfwh(authNoAllKindVO.getEduBtgNumYfwh());
                    statisticsVO.setEduBtgNumYhwf(authNoAllKindVO.getEduBtgNumYhwf());

                    statisticsVO.setEduBtgNumHj(authNoAllKindVO.getEduBtgNumHj());
                    statisticsVO.setEduBtgNumFc(authNoAllKindVO.getEduBtgNumFc());
                    statisticsVO.setEduBtgNumSb(authNoAllKindVO.getEduBtgNumSb());
                    statisticsVO.setEduBtgNumJzz(authNoAllKindVO.getEduBtgNumJzz());
                    statisticsVO.setEduBtgNumZcap(authNoAllKindVO.getEduBtgNumZcap());


                    statisticsVO.setSchoolTgNum(authNoAllKindVO.getSchoolTgNum());
                    statisticsVO.setSchoolTgNumFhyz(authNoAllKindVO.getSchoolTgNumFhyz());
                    statisticsVO.setSchoolTgNumFhyzFwq(authNoAllKindVO.getSchoolTgNumFhyzFwq());
                    statisticsVO.setSchoolTgNumYfwh(authNoAllKindVO.getSchoolTgNumYfwh());
                    statisticsVO.setSchoolTgNumYhwf(authNoAllKindVO.getSchoolTgNumYhwf());

                    statisticsVO.setSchoolTgNumHj(authNoAllKindVO.getSchoolTgNumHj());
                    statisticsVO.setSchoolTgNumFc(authNoAllKindVO.getSchoolTgNumFc());
                    statisticsVO.setSchoolTgNumSb(authNoAllKindVO.getSchoolTgNumSb());
                    statisticsVO.setSchoolTgNumJzz(authNoAllKindVO.getSchoolTgNumJzz());
                    statisticsVO.setSchoolTgNumZcap(authNoAllKindVO.getSchoolTgNumZcap());


                }

                Integer schoolBtgNum = statisticsVO.getSchoolBtgNum()== null? 0:statisticsVO.getSchoolBtgNum();
                statisticsVO.setSchoolAuditNum(statisticsVO.getSchoolDshNum() + statisticsVO.getSchoolTgNum() + schoolBtgNum);
                Integer eduBtgNum = statisticsVO.getEduBtgNum()== null? 0:statisticsVO.getEduBtgNum();
                //教育局待审核=学校审核通过
               // statisticsVO.setEduAuditNum(statisticsVO.getEduDshNum() + statisticsVO.getEduTgNum() + eduBtgNum);
                statisticsVO.setEduAuditNum(statisticsVO.getSchoolTgNum() + statisticsVO.getEduTgNum() + eduBtgNum);
            }


        }
        dictHelper.valueToName(pageInfo.getList(), Arrays.asList(EduEnrollPreDictEnum.values()));
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0008", title = "学校各类招生情况统计导出", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downAllKindStatistic(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setJhData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0039", title = "同学段不同街道学校关联相同地址详情", funcType = FuncTypeEnum.query)
    public PageInfo<SameAddressSchoolDetailVO> sameAddressSchoolStreet(EnrollStudentQueryVO vo) {
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<SameAddressSchoolDetailVO> list = eduStudentEnrollService.sameAddressSchoolStreet(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<SameAddressSchoolDetailVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


    @Override
    @OpApi(funcCode = "DyEnrollData0049", title = "学校同学段不同街道学校关联相同地址详情", funcType = FuncTypeEnum.query,checkPrivilege = BoolEnum.FALSE)
    public PageInfo<SameAddressSchoolDetailVO> sameAddressSchoolStreetSchool(EnrollStudentQueryVO vo) {
        String schoolId = SessionUtil.getOrgId();
        if (StringUtils.isBlank(schoolId)) {
            throw new AppException("当前账号未绑定学校");
        }
        EduSchoolVO school = eduSchoolService.getDetail(schoolId);
        if (ObjectUtils.isEmpty(school)){
            throw new AppException("该学校不存在，数据异常！");
        }
        vo.setSchoolId(school.getOrgId());
        vo.setSchoolCategory(school.getSchoolCategory());
        // 开启分页
        if (vo.getPageNum() == null || vo.getPageSize() == null) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(50);
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            vo.setAreaCode(SessionUtil.getAreaCode());
        }
        if (vo.getYear() == null) {
            vo.setYear(eduHelper.thisYear());
        }
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<SameAddressSchoolDetailVO> list = eduStudentEnrollService.sameAddressSchoolStreetSchool(vo);
        if (CollectionUtils.isEmpty(list)) {
            // 判断是否为空，为空则返回空参数
            return PagerUtil.createEmptyPagerInfo(vo.getPageNum(), vo.getPageSize());
        }
        PageInfo<SameAddressSchoolDetailVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0040", title = "同学段不同街道学校关联相同地址详情导出", funcType = FuncTypeEnum.query)
    @NoSignCrypto
    public void downsameAddressSchoolStreet(EnrollStudentQueryVO vo, HttpServletResponse response) {
        ExcelVO excelVO = new ExcelVO();
        excelVO.setModelCode(vo.getModelCode());
        ExcelModelVO excelModelVO = excelIntegration.getModel(excelVO);

        String destFilePath = this.tempPath + "/" + IdUtil.fastSimpleUUID() + "." + excelModelVO.getExcelType();
        int pageNum = 1;
        setJhData(excelModelVO, null, destFilePath, vo, pageNum);
        String fileName = vo.getFileName();
        if (StringUtils.isBlank(fileName)) {
            fileName =
                    excelModelVO.getModelName()
                            + "_"
                            + DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN)
                            + "."
                            + (StringUtils.isBlank(excelModelVO.getExcelType())
                            ? "xls"
                            : excelModelVO.getExcelType());
        }
        File file = FileUtil.file(destFilePath);
        BufferedInputStream in = null;
        try {
            in = FileUtil.getInputStream(file);
            ServletUtil.write(response, in, "application/octet-stream;charset=utf-8", fileName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileUtil.del(destFilePath);
        }
    }

    @Override
    @OpApi(funcCode = "DyEnrollData0041", title = "同学段不同街道学校关联相同地址详情生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public void createSameAddressSchoolStreet(EnrollStudentQueryVO vo) {
        LambdaQueryWrapper<EduAddressSchoolDifferentStreet> queryWrapper = new LambdaQueryWrapper<>();
        List<EduAddressSchoolDifferentStreet> list_del = differentStreetService.list(queryWrapper);
        if(!CollectionUtils.isEmpty(list_del)){
            differentStreetMapper.delete(queryWrapper);
        }

        List<SameAddressSchoolDetailVO> saveList =  eduStudentEnrollService.getEduAddressSchoolDifferentStreet(vo);
        if(!CollectionUtils.isEmpty(saveList)){
            saveList.forEach(item->{
                EduAddressSchoolDifferentStreet differentStreet = new EduAddressSchoolDifferentStreet();
                copyProperties(item,differentStreet);
                differentStreetService.save(differentStreet);
            });
        }
    }


    private void setJhData(ExcelModelVO excelModelVO, ExcelWriter excelWriter, String destFilePath, EnrollStudentQueryVO vo, int pageNum) {
        vo.setPageNum(pageNum);
        vo.setPageSize(500);
        boolean closeFlag = false;
        try {
            String total = "0";
            boolean hasNextPage = false;
            List<Map<String, Object>> list = new ArrayList<>();
            if (StringUtils.isNotBlank(vo.getModelCode())) {
                if (vo.getModelCode().equals("queryNoEnrollStudent")) {
                    PageInfo<NoEnrollStudentVO> pageInfo = queryNoEnrollStudent(vo);
                    total = String.valueOf(pageInfo.getTotal());
                    if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                        for (NoEnrollStudentVO studentVO : pageInfo.getList()) {
                            list.add(BeanUtil.beanToMap(studentVO, false, true));
                        }
                    }
                    hasNextPage = pageInfo.isHasNextPage();
                }
                if (vo.getModelCode().equals("noAssociatedAddress")) {
                    PageInfo<NoAssociatedAddressVO> pageInfo = noAssociatedAddress(vo);
                    total = String.valueOf(pageInfo.getTotal());
                    if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                        for (NoAssociatedAddressVO addressVO : pageInfo.getList()) {
                            list.add(BeanUtil.beanToMap(addressVO, false, true));
                        }
                    }
                    hasNextPage = pageInfo.isHasNextPage();
                }
                if (vo.getModelCode().equals("sameAddressSchool")) {
                    PageInfo<SameAddressSchoolVO> pageInfo = sameAddressSchool(vo);
                    total = String.valueOf(pageInfo.getTotal());
                    if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                        for (SameAddressSchoolVO addressVO : pageInfo.getList()) {
                            list.add(BeanUtil.beanToMap(addressVO, false, true));
                        }
                    }
                    hasNextPage = pageInfo.isHasNextPage();
                }
                if (vo.getModelCode().equals("sameAddressSchoolDetail")) {
                    PageInfo<SameAddressSchoolDetailVO> pageInfo = sameAddressSchoolDetail(vo);
                    total = String.valueOf(pageInfo.getTotal());
                    if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                        for (SameAddressSchoolDetailVO addressVO : pageInfo.getList()) {
                            list.add(BeanUtil.beanToMap(addressVO, false, true));
                        }
                    }
                    hasNextPage = pageInfo.isHasNextPage();
                }
                if (vo.getModelCode().equals("serverRelationButNoAssociatedAddress")) {
                    PageInfo<ServerRelationNoSchoolRelataionVO> pageInfo = serverRelationButNoAssociatedAddress(vo);
                    total = String.valueOf(pageInfo.getTotal());
                    if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                        for (ServerRelationNoSchoolRelataionVO addressVO : pageInfo.getList()) {
                            list.add(BeanUtil.beanToMap(addressVO, false, true));
                        }
                    }
                    hasNextPage = pageInfo.isHasNextPage();
                }

                if (vo.getModelCode().equals("bmAllKindGb")||vo.getModelCode().equals("bmAllKindMb")) {
                    PageInfo<EnrollStatisticsVO> pageInfo = allKindStatistic(vo);
                    total = String.valueOf(pageInfo.getTotal());
                    if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                        for (EnrollStatisticsVO statisticsVO : pageInfo.getList()) {
                            list.add(BeanUtil.beanToMap(statisticsVO, false, true));
                        }
                    }
                    hasNextPage = pageInfo.isHasNextPage();
                }
                if (vo.getModelCode().equals("sameAddressSchoolStreet")) {
                    PageInfo<SameAddressSchoolDetailVO> pageInfo = sameAddressSchoolStreet(vo);
                    total = String.valueOf(pageInfo.getTotal());
                    if (!CollectionUtils.isEmpty(pageInfo.getList())) {
                        for (SameAddressSchoolDetailVO addressVO : pageInfo.getList()) {
                            list.add(BeanUtil.beanToMap(addressVO, false, true));
                        }
                    }
                    hasNextPage = pageInfo.isHasNextPage();
                }
            } else {
                throw new AppException("导出类型未开发相应功能");
            }

            if (pageNum == 1) {
                if (excelWriter == null) {
                    excelWriter = excelCommonHelper.createExcelWriter(excelModelVO, destFilePath, Integer.parseInt(total));
                }
                excelCommonHelper.writeMap(excelWriter, list);
            } else {
                excelCommonHelper.writeMap(excelWriter, list);
            }
            if (hasNextPage) {
                pageNum = pageNum + 1;
                setJhData(excelModelVO, excelWriter, destFilePath, vo, pageNum);
            } else {
                closeFlag = true;
            }
        } catch (AppException appEx) {
            throw appEx;
        } catch (Exception e) {
            throw new AppException("调用自定义写入服务异常:" + e.getMessage());
        } finally {
            if (closeFlag && excelWriter != null) {
                excelWriter.close();
            }
        }
    }


}
